﻿
using System;
using System.Configuration;
using System.Web;
namespace FTchina
{
    /// <summary>
    /// UImsg 的摘要说明
    /// </summary>
    public class UImsg
    {
        /// <summary>
        /// 页面错误提示信息
        /// </summary>
        /// <param name="ErrMsg">错误信息</param>
        /// <param name="Url">返回管理员地址  默认可以填写:""或"0"</param>
        public static void PageError(string ErrMsg, string Url)
        {


            string STitle = "操作失败信息";
            string _tmp = "<img src=\"/images/error.gif\" border=\"0\">";
            string SCaption = "<font color=\"red\" size=3>×抱歉！操作失败</font>";

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r <META http-equiv='refresh' content='2;url=" + DelParFromUrl(Url) + "'>\r");
            HttpContext.Current.Response.Write("<link href=\"/images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body  bgcolor='#ffffff'>\r");
            HttpContext.Current.Response.Write("<table width='40%' border='1' style='border-collapse: collapse;'  bordercolor='#cccccc' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" >" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\"  >" + _tmp + "<br /><br /></td><td class=\"list_link\" ><font color=red>操作描述：</font>\r");
            HttpContext.Current.Response.Write("<ul>");
            HttpContext.Current.Response.Write("<li><span>" + ErrMsg + "</span></li></ul>\r");
            HttpContext.Current.Response.Write("    </td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="StrUrl"></param>
        /// <returns></returns>
        private static string UserUrl(string StrUrl)
        {
            if (StrUrl == "0" || StrUrl == "")
            {
                StrUrl = "<a href='/'><b>返回首页</b></a>";
            }
            else
            {
                StrUrl = "<a href='" + StrUrl + "' target=_parent><b>返回管理</b></a>";
            }
            return StrUrl;
        }

        /// <summary>
        /// 页面操作成功提示信息
        /// </summary>
        /// <param name="RightMsg">操作成功信息</param>
        /// <param name="Url">返回管理员地址</param>
        public static void PageRight(string RightMsg, string Url)
        {
            PageRender(RightMsg, Url, true);
        }

        public static void PageRender(string Msg, string Url, bool Succeed)
        {
            string STitle = "操作成功信息";
            string _tmp = "<img src=\"../images/success.gif\" border=\"0\">";
            string SCaption = "√恭喜！操作成功";
            if (!Succeed)
            {
                STitle = "操作失败信息";
                _tmp = "<img src=\"../images/error.gif\" border=\"0\">";
                SCaption = "<font color=\"red\">×抱歉！操作失败</font>";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r");
            HttpContext.Current.Response.Write("<link href=\"../images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body>\r");
            HttpContext.Current.Response.Write("<table width='100%' border='0' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" colspan=\"2\">" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\"  >" + _tmp + "<br /><br /></td><td class=\"list_link\" ><font color=red>操作描述：</font>\r");
            HttpContext.Current.Response.Write("<ul>");
            HttpContext.Current.Response.Write("<li><span>" + Msg + "</span></li><li><a href='" + DelParFromUrl(HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]) + "' class='list_link'><b>返回继续操作</b></a>&nbsp;&nbsp;&nbsp;&nbsp;" + UserUrl(Url) + "</li></ul>\r");
            HttpContext.Current.Response.Write("    </td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }

        public static void PageRender(string Msg, bool Succeed)
        {
            string STitle = "操作提示信息";
            string _tmp = "<img src=\"/images/success.gif\" border=\"0\">";
            string SCaption = "√恭喜！操作成功";
            if (!Succeed)
            {
                STitle = "操作失败信息";
                _tmp = "<img src=\"/images/error.gif\" border=\"0\">";
                SCaption = "<font color=\"red\">×抱歉！操作失败</font>";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r");
            HttpContext.Current.Response.Write("<link href=\"/images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body>\r");
            HttpContext.Current.Response.Write("<table width='100%' border='0' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" colspan=\"2\">" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\"  >" + _tmp + "<br /><br /></td><td class=\"list_link\" ><font color=red>操作描述：</font>\r");
            HttpContext.Current.Response.Write("<ul>");
            HttpContext.Current.Response.Write("<li><span>" + Msg + "</span></li><li><a href='" + DelParFromUrl(HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]) + "' class='list_link'><b>返回继续操作</b></a></li></ul>\r");
            HttpContext.Current.Response.Write("    </td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }
        public static void PageRender(bool Succeed)
        {
            string STitle = "操作提示信息";
            string _tmp = "<img src=\"../images/success.gif\" border=\"0\">";
            string SCaption = "<font color=\"green\" size=3>√恭喜！操作成功</font>";
            if (!Succeed)
            {
                STitle = "操作失败信息";
                _tmp = "<img src=\"../images/error.gif\" border=\"0\">";
                SCaption = "<font color=\"red\" size=3>×抱歉！操作失败</font>";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r <META http-equiv='refresh' content='2;url=" + DelParFromUrl(HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]) + "'>\r");
            HttpContext.Current.Response.Write("<link href=\"../images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body  bgcolor='#ffffff'>\r");
            HttpContext.Current.Response.Write("<table width='40%' border='1' style='border-collapse: collapse;'  bordercolor='#cccccc' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" >" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\" >" + _tmp + "<br /><br />请稍等，马上返回");
            HttpContext.Current.Response.Write("</td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }
        public static void PageRender(bool Succeed, string url)
        {
            string STitle = "操作提示信息";
            string _tmp = "<img src=\"/images/success.gif\" border=\"0\">";
            string SCaption = "<font color=\"green\" size=3>√恭喜！操作成功</font>";
            if (!Succeed)
            {
                STitle = "操作失败信息";
                _tmp = "<img src=\"/images/error.gif\" border=\"0\">";
                SCaption = "<font color=\"red\" size=3>×抱歉！操作失败</font>";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r <META http-equiv='refresh' content='2;url=" + url + "'>\r");
            HttpContext.Current.Response.Write("<link href=\"../images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body  bgcolor='#ffffff'>\r");
            HttpContext.Current.Response.Write("<table width='40%' border='1' style='border-collapse: collapse;'  bordercolor='#cccccc' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" >" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\" >" + _tmp + "<br /><br />请稍等，马上返回");
            HttpContext.Current.Response.Write("</td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }

        public static void PageRender(string Msg)
        {
            string STitle = "操作提示信息";
            string _tmp = "<img src=\"../images/ok.gif\" border=\"0\">";
            string SCaption = "操作信息反馈";

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("<html xmlns='http://www.w3.org/1999/xhtml' >\r<head>\r");
            HttpContext.Current.Response.Write("<title>" + STitle + "</title>\r ");
            HttpContext.Current.Response.Write("<link href=\"../images/uicss.css\" rel=\"stylesheet\" type=\"text/css\" />\r");
            HttpContext.Current.Response.Write("\r</head><body>\r");
            HttpContext.Current.Response.Write("<table width='100%' border='1' style='border-collapse: collapse;'  bordercolor='#cccccc' align=\"center\" cellspacing=\"1\" cellpadding=\"5\" class=\"table\"  style=\"height:180px;margin-top:80px\"><tr class=\"hback\"><td class=\"hback\" style=\"height:38px;\" colspan=\"2\">" + SCaption + "</td>\r");
            HttpContext.Current.Response.Write("</tr><tr class=\"hback\"><td align=\"center\" >" + _tmp + "<br /><br /></td><td class=\"list_link\" ><font color=red>操作描述：</font>\r");
            HttpContext.Current.Response.Write("<ul>");
            HttpContext.Current.Response.Write("<li><span>" + Msg + "</span></li><li><a href='" + DelParFromUrl(HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]) + "' class='list_link'><b>返回继续操作</b></a></li></ul>\r");
            HttpContext.Current.Response.Write("    </td></tr>\r</table>\r");
            HttpContext.Current.Response.Write("</body>\r</html>\r");
            HttpContext.Current.Response.End();
        }



        /// <summary>
        /// 去除url中的参数
        /// </summary>
        /// <returns></returns>
        private static string DelParFromUrl(string url)
        {

            string temp = url;

            if (url.Length != null)
            {
                if (url.Contains("?"))
                {
                    temp = url.Split('?')[0];
                }
            }

            return temp;
        }
    }

}